package com.xuqi.Bluetooth;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import android.R.integer;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.xuqi.R;
import com.xuqi.menucontrol.SCR_MenuBase;

public class BluetoothDeviceList extends SCR_MenuBase
{

	final int REQUEST_ENABLE_BT = 1111;
	BluetoothAdapter m_BluetoothAdapter = null;
	List<String> m_data = null;
	private ListView m_listView;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bluetoothlist);
		m_listView = (ListView) findViewById(R.id.listView1);
		m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
		getList();
		m_listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, m_data));
	}


	public void getList()
	{
		m_data = new ArrayList<String>();
		Set<BluetoothDevice> pairedDevices = m_BluetoothAdapter.getBondedDevices();
		// If there are paired devices
		if (pairedDevices.size() > 0)
		{
			// Loop through paired devices
			for (BluetoothDevice device : pairedDevices)
			{
				// Add the name and address to an array adapter to show in a
				// ListView
				m_data.add(device.getName() + "\n" + device.getAddress());
			}
		}
	}

}
